package sheshen.come.cn.sheshen.utils;

import android.app.Dialog;
import android.content.Context;
import android.content.res.Resources;
import android.os.Build;
import android.support.v7.app.AlertDialog;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;

import sheshen.come.cn.sheshen.R;

/**
 * Created by MyPC on 2017/2/23.
 */

public class Tools {
    private static Context context;
    private static Dialog ad;
    private static TextView tv;
    /**
     * 初始化注入Context对象
     */
    public static void setContext(Context context) {
        Tools.context = context;
    }

    /**
     *创建自定义对话框
     * @param view
     * @param context
     */
    public static void showCustomDialog(View view, Context context) {
        showCustomDialog(context, true, 0, 0, ((getsx())), (getsy()), view);
    }
    public static int getsx() {
        return context.getResources().getDisplayMetrics().widthPixels;
    }

    public static int getsy() {
        int px = Resources.getSystem().getDimensionPixelSize(Resources.getSystem().getIdentifier("status_bar_height", "dimen", "android"));
        return context.getResources().getDisplayMetrics().heightPixels - px;
    }
    /**
     *
     * @param cancleAble
     * @param x
     * @param y
     * @param width
     * @param height
     * @param view
     * @return
     */
    public static Dialog showCustomDialog(Context context, boolean cancleAble, int x, int y, int width, int height, View view) {
        if (Build.VERSION.SDK_INT >= 11) {
            ad = new AlertDialog.Builder(context, R.style.dialog).create();
        } else {
            ad = new Dialog(context, R.style.alert_dialog);
        }
        ad.setCancelable(cancleAble);
        ad.show();
        ad.setContentView(view);
        ad.getWindow().setLayout(width, height);
        ad.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
        return ad;
    }
    /**
     * 取消等待的dialog
     */
    public static void dismissWaitDialog() {
        if (ad != null)
            ad.dismiss();
    }
}
